<?php
namespace app\app\controller\v2;
use app\app\Appbase;
use think\facade\Session;
use think\facade\Cache;

class Staff extends Appbase 
{
	
	/**
	*获取店员列表
	* /app/v2/staff/getList
	* 需要登录 
	* @is_need_login true
	*/
	public function getList(){
		
		try {
			$result = model('ShopStaff')->getList( request()->shopInfo['id'] );
			return $this->ReSucess($result);	
			
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
		
	}
	
	/**
	*添加店员
	* /app/v2/staff/add
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function add(){
		$request =  request();
		$param = $request ->post();
		$param['shop_id'] = $request ->shopInfo['id'];
		
		try {
			$result = model('ShopStaff')->add($param);
			if($result === false){
				return $this->ReError( model('ShopStaff')->errorInfo );
			}
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	*编辑店员
	* /app/v2/staff/edit
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function edit(){
		$request =  request();
		$param = $request ->post();
		try {
			$result = model('ShopStaff')->edit($param);
			if($result === false){
				return $this->ReError( model('ShopStaff')->errorInfo );
			}
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
	/**
	*删除店员
	* /app/v2/staff/del
	* 需要登录 
	* @is_need_login true
	*/
	public function del($id){
		try {
			$result = model('ShopStaff')->del(request()->shopInfo['id'],$id);
			if(!$result){
				return $this->ReError();
			}
			return $this->ReSucess("删除成功！");	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
}



